<template>
	<view>
		<view class="content">
			 <view class="userinfo">
				  <view>
					  <image v-if="type!=2"  :src="avatarUrl?avatarUrl:error"  mode=""></image>
					  <image v-if="type==2"  src="../../static/images/user.png" mode=""></image>
					  <view>
						<view v-if="type!=2" class="username">{{name?name:''}}</view>
						<view>卡点点欢迎您</view>
					  </view>
					  
				  </view>
			 </view>
			 <view class="order">
				   <view>
					   <text>我的转让</text>
					   <text> </text>
				   </view>
				   <view>
					   <view>
						   <text>{{chulizhong ? chulizhong : 0}}</text>
						   <text>处理中</text>
					   </view>
					   <view>
						   <text>{{totalToday ? totalToday : 0}}</text>
						   <text>今日笔数</text>
					   </view>
					   <view>
						   <text>{{cgbs ? cgbs : 0}}</text>
						   <text>今日成功</text>
					   </view>
					   <view>
						   <text>{{sbbs ? sbbs : 0}}</text>
						   <text>今日失败</text>
					   </view>
					   <view>
						   <text>{{deal ? deal : 0}}</text>
						   <text>今日收入</text>
					   </view>									  
				   </view>
			 </view>
			 
			 <view class="nav">
				 <view @click="goAccount" class="n1">
					  <view>
						  <image src="../../static/images/zhuanzhangshezhi.png"></image>
						  <text>转账设置</text>
					  </view>
					  <image src="../../static/images/you.png"></image>
				 </view>
				 <view @click="orderhis" class="n1">
					  <view>
						  <image src="../../static/images/dingdanjilu.png"></image>
						  <text>交易记录</text>
					  </view>
					  <image src="../../static/images/you.png"></image>
				 </view>
				 <view  @click="goUserInfo" class="n1">
					  <view>
						  <image src="../../static/images/a7.png"></image>
						  <text>隐私服务</text>
					  </view>
					  <image src="../../static/images/you.png"></image>
				 </view>
				 <view @click="goCallUs" class="n1">
					  <view>
						  <image src="../../static/images/lianxiwomen.png"></image>
						  <text>联系我们</text>
					  </view>
					  <image src="../../static/images/you.png"></image>
				 </view>
				  <view @click="goInvite" class="n1">
					   <view>
						   <image src="../../static/images/woyaofenxiao.png"></image>
						   <text>我要分享</text>
					   </view>
					   <image src="../../static/images/you.png"></image>
				  </view>
			 </view>
			 
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:'',
				token:'',//onShow时获取token存起来，以便每次发送请求都要重新获取
				rebateMoney:'',
				name:'',
				phone:'',
				avatarUrl:'',
				error:require('../../static/images/0d4cffca476d4fcafd20a4da7853b9f.png'),
				totalToday:'',//今日笔数
				cgbs:'',//成功笔数
				sbbs:'',//失败笔数
				chulizhong:'',//处理中,
				deal: ''// 今日收入
			}
		},
		onShareAppMessage(res) {
			let that=this;
			if (res.from === 'button') {// 来自页面内分享按钮
			}
			return {
				     　 title: "",      
				　　　　path: '/pages/index/index?parentid='+that.token,       
				　　　　imageUrl: '',     
			}
		},
		onShow(){
			this.type=this.type_
			if(this.type_==2){
				AlipayJSBridge.call('setTitle', {
				      title: '专注卡券回收服务—卖卡啦'
				    });
			}
			uni.showShareMenu();
			this.token = uni.getStorageSync('token')
			let _this = this
			
			if(this.type_==1){
				if(!this.token){
					uni.navigateTo({
						url: '../login/login'
					})
					return 
				}
				if(this.token){
					uni.request({
						url: this.url + '/mobile/realData',
						method:'GET',
						header: {
							'content-type': 'application/x-www-form-urlencoded' ,// 默认值
							'token': this.token
						},
						data:{
							
						},
						success: (res) => {
							this.rebateMoney = res.data.rebateMoney+''
							if(res.data.realName!=''){
							  _this.name = res.data.realName+''
							}else{
							 _this.name = res.data.name+''
							}
							_this.phone = res.data.tel+''
							 
						}
					})
				}
			}else if(this.type_==2){
				uni.request({
					url: _this.url + '/mobile/realData',
					method:'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,// 默认值
						'token': this.token
					},
					data:{
						
					},
					success: (res) => {
						_this.rebateMoney = res.data.rebateMoney+''
						_this.name = res.data.name+''
						_this.phone = res.data.tel+''
					}
				})
			}else{
				// 微信小程序登录
				uni.login({
					provider: 'weixin',
					success: function (res) {
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: function (res) {
								_this.name = res.userInfo.nickName
								_this.avatarUrl = res.userInfo.avatarUrl
							},
							fail(res) {  //小程序第一次授权自动失败  进入授权页面
								 uni.redirectTo({
								 	url:'../empower/empower'
								 })
								 return;		 
							}
						});
						uni.request({
							url: _this.url + '/applet/getSessionKey',
							method:'GET',
							header: {
								'content-type': 'application/x-www-form-urlencoded' ,// 默认值
							},
							data:{
								code:res.code
							},
							success: (res) => {
								console.log("---getSessionKey---")
								console.log(res)
								uni.setStorageSync('token',res.data.data.token)
								_this.token = res.data.data.token
								uni.request({
									url: _this.url + '/mobile/realData',
									method:'GET',
									header: {
										'content-type': 'application/x-www-form-urlencoded' ,// 默认值
										'token': res.data.data.token
									},
									data:{
										
									},
									success: (res) => {
										_this.rebateMoney = res.data.rebateMoney+''
										//_this.name = res.data.name+''
										_this.phone = res.data.tel+''
									}
								})
								uni.request({
									url: _this.url + '/mobile/balanceStatistical',
									method:'GET',
									header: {
										'content-type': 'application/x-www-form-urlencoded' ,// 默认值
										'token': res.data.data.token
									},
									data:{
										
									},
									success: (res) => {
										if (res.data.result) {
											var _data = res.data.data
											if (_data) {
												_this.deal = _data.deal
												_this.totalToday = _data.totalToday
												_this.cgbs = _data.cgbs
												_this.sbbs = _data.sbbs
												_this.chulizhong = _data.chulizhong
											}
										}
									}
								})
							},
						})
					},
				})
			}

	
		},
		mounted() {
			
		},
		methods: {
			out(){
				uni.clearStorageSync()
				uni.navigateTo({
					url: '../login/login'
				});
			},
			orderhis(){
				uni.switchTab({
					url:'../order/order'
				})
			},
			goCallUs(){
				uni.navigateTo({
					url: '../callUs/callUs'
				})
			},
			goCompany_recovery(){//跳转企业回收页面
				uni.navigateTo({
					url: '../company_recovery/company_recovery'
				})
			},
			goFind_shoper(){//跳转招商合作页面
				uni.navigateTo({
					url: '../find_shoper/find_shoper'
				})
			},
			goProblem_often(){//跳转常见问题页面
				uni.navigateTo({
					url: '../problem_often/problem_often'
				})
			},
			// 跳转到推广页面
			goInvite(){
				uni.navigateTo({
					url: '../invite/invite'
				});
			},
			goUserInfo(){//跳转个人信息页面
				uni.navigateTo({
					url: '../userInfo/userInfo'
				});
			},
			goAccount(){//跳转打款账户页面
				uni.navigateTo({
					url: '../account/account'
				});
			},
			goCommission(){//跳转佣金记录页面
				uni.navigateTo({
					url: '../commission/commission'
				});
			},
			goFeedback(){//跳转意见反馈页面
				uni.navigateTo({
					url: '../feedback/feedback'
				});
			},
			goRecord(){//跳转提现记录页面
				uni.navigateTo({
					url: '../record/record'
				});
			},
			goWithdrawDeposit(){//跳转体现页面
				uni.navigateTo({
					url: '../withdrawDeposit/withdrawDeposit'
				});
			}
		}
	}
</script>

<style>
page{
	background-color:#F2F2F2 ;
	padding-bottom: 100upx;
}
.userinfo{
	width:100%;
	height:330upx;
	background:#1e90ff;
	color:#fff;
}
.userinfo image{
	width:160upx;
	height:160upx;
	border-radius: 50%;
	margin-left:80upx;
	margin-right:30upx;
}
.userinfo>view{
	display: flex;
	align-items: center;
	font-size: 36upx;
	padding-top: 33upx;
}
.order{
	width: 95%;
	margin: auto;
	background-color: #fff;
	box-sizing: border-box;
	padding: 13upx 25upx;
	border-radius: 13upx;
	margin-top: -10%;
}
.order>view:nth-child(1){
	width:100%;
	margin: auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 35upx;
	border-bottom: 1upx solid #e3e3e3;
	padding-bottom:15upx;
}
.order>view:nth-child(2){
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10upx 10upx 20upx 10upx;
	box-sizing: border-box;
}
.order>view:nth-child(2)>view{
	display: flex;
	flex-direction: column;
	align-items: center;
}
.nav{
	width: 100%;
	margin-top: 15upx;
}
.n1{
	width: 100%;
	display: flex;
	justify-content: space-between;
	background: #fff;
	align-items: center;
	padding:18upx 18upx 18upx 25upx;
	box-sizing: border-box;
	border-bottom: 1upx solid #F2F2F2;
}
.n1>view{
	display: flex;
	align-items: center;
	font-size: 35upx;
}
.n1>view>image{
	width: 50upx;
	height:50upx;
	margin-right:20upx;
}
.n1>image{
	width: 50upx;
	height: 50upx;
}
</style>
